<?PHP
require_once("../include/XMLSports.php");
require_once("../include/functions.php");
//Connect To Database
dbConnect();

//check to see if a League value was passed, if not, use NFL by default.
if (($League == NULL) || ($League == ""))
	$League = "NHL";
//check to see if a year value was passed, if not, lookup in DB and set to current season year.
if (($year == NULL) || ($year == ""))
	$year = getSeasonYear($League);

//check to see if a Weeknum value was passed, if not, set WeekNum to CurrWeek.
//if (($Weeknum == NULL) || ($Weeknum == ""))
//	$Weeknum = getWeek($League);

//check to make sure $Weeknum > 1 AND $Weeknum < 21
//$Weeknum = checkWeekBounds($Weeknum);

//check to see if a Weeknum value was passed, if not, set WeekNum to CurrWeek.
if (($scrapeDate == NULL) || ($scrapeDate == ""))
	$scrapeDate = date("Ymd");

echo "State|";
#echo "<br/>Scraping $year $League, date = $scrapeDate<br/>";

$filename = "../".$League."/rss/".$year."/".$scrapeDate.".xml";
#echo "Filename = $filename<br/>";
//Create New XMLSports Generator
$myXMLSports = new XMLSports;
//Set the Current WEEK
$myXMLSports->SetWeek($scrapeDate);
//Set the League
$myXMLSports->SetLeague($League);
//Set the SeasonYear
$myXMLSports->SetSeason($year);
//Set Output File Name
$myXMLSports->setOutputFile($filename);
//Generate The New SportsML XML file
$myXMLSports->generate();
$timeAdjust = 5; //Number of hours From GMT + or - to be added
$timeAdjust += date("I");
$timeAdjust *= 60;	//60 minutes in an hour
$timeAdjust *= 60;	//60 seconds in an minute
echo "Last scraped at <b>".gmdate("g:i:s a \E\T", time() - $timeAdjust)."</b>...<br/>";

?>
